package com.finace.management.service.impl;
import java.util.List;

import com.finace.pojo.TbClusterExample;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.finace.mapper.TbClusterMapper;
import com.finace.pojo.TbCluster;
import com.finace.pojo.TbClusterExample;
import com.finace.pojo.TbClusterExample.Criteria;
import com.finace.management.service.ClusterService;

import com.entity.PageResult;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class ClusterServiceImpl implements ClusterService {

	@Autowired
	private TbClusterMapper clusterMapper;
	
	/**
	 * 查询全部
	 */
	@Override
	public List<TbCluster> findAll() {
		return clusterMapper.selectByExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);		
		Page<TbCluster> page=   (Page<TbCluster>) clusterMapper.selectByExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(TbCluster cluster) {
		clusterMapper.insert(cluster);		
	}

	
	/**
	 * 修改
	 */
	@Override
	public void update(TbCluster cluster){
		clusterMapper.updateByPrimaryKey(cluster);
	}	
	
	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public TbCluster findOne(int id){
		return clusterMapper.selectByPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(int[] ids) {
		for(int id:ids){
			clusterMapper.deleteByPrimaryKey(id);
		}		
	}
	
	
		@Override
	public PageResult findPage(TbCluster cluster, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		
		TbClusterExample example=new TbClusterExample();
		Criteria criteria = example.createCriteria();
		
		if(cluster!=null){			
						if(cluster.getqName()!=null && cluster.getqName().length()>0){
				criteria.andQNameLike("%"+cluster.getqName()+"%");
			}
	
		}
		
		Page<TbCluster> page= (Page<TbCluster>)clusterMapper.selectByExample(example);		
		return new PageResult(page.getTotal(), page.getResult());
	}
	
}
